package com.archive.forum.dto;

import com.archive.forum.exception.BaseErrorInfoInterface;
import com.archive.forum.exception.CustomizeException;
import lombok.Data;

@Data
public class ResultDTO<T> {
    private String code;
    private String message;
    private T data;

    public static ResultDTO errorOf(String code, String message) {
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode(code);
        resultDTO.setMessage(message);
        return resultDTO;
    }
    public static ResultDTO errorOf(BaseErrorInfoInterface errorInfoInterface) {
        return errorOf(errorInfoInterface.getResultCode(),errorInfoInterface.getResultMsg());
    }
    public static ResultDTO errorOf(CustomizeException e) {
        return errorOf(e.getErrorCode(),e.getErrorMsg());
    }
    public static ResultDTO okOf() {
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode("2000");
        resultDTO.setMessage("请求成功");
        return resultDTO;
    }
    public static <T> ResultDTO okOf(T t) {
        ResultDTO resultDTO = new ResultDTO();
        resultDTO.setCode("2000");
        resultDTO.setMessage("请求成功");
        resultDTO.setData(t);
        return resultDTO;
    }
}
